package chars;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;

public class WriterTest1 {

	public static void main(String[] args) throws IOException {
		
		File file = new File( "writer.txt" );
		
		OutputStream output = new FileOutputStream( file );
		
		
		// 声明一个可以输出字符的输出流
		Writer w = null ;
		
		Charset charset = Charset.forName( "UTF-8" );
		
		// 创建一个可以将 字符 按照指定的 charset 编码为 字节的 输出流
		w = new OutputStreamWriter( output , charset );
		
		w.write( '中' ); // 输出单个字符
		w.write( '国' );
		w.write( '\n' );
		
		char[] chars = { '不' , '破' , '楼' , '兰' , '终' , '不' , '还' };
		w.write( chars );
		w.write( '\n' );
		
		w.write( chars , 4 , 3 );
		w.write( '\n' );
		
		w.write( "黄沙百战穿金甲" );
		w.write( '\n' );
		
		w.close(); // w.flush();
		
		output.close();

	}

}
